package com.gs.wzmanager.config.webmvc;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/10/30 0030
 */
//@Component
    //@PostConstruct注解等效
public class InstantExecution implements ApplicationListener<ContextRefreshedEvent> {

    public void onApplicationEvent(ContextRefreshedEvent event) {
        //避免server初始化与容器初始化过程执行两次
        if (event.getApplicationContext().getParent() == null) {

            //需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。
        }
    }
}
